package com.atguigu.guli.service.edu.controller.admin;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.feign.OssFileFeignClient;
import com.atguigu.guli.service.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/params")
public class AdminTestController {

    @Autowired
    OssFileFeignClient ossFileFeignClient;

    @GetMapping("testFeignClient1")
    public R testFeignClient1(){
        R r = ossFileFeignClient.test1();
        return r;
    }

    @GetMapping("testFeignClient2")
    public R testFeignClient2(){
        R r = ossFileFeignClient.test2("jack");
        return r;
    }

    @Autowired
    TeacherService teacherService;
    @PostMapping("testFeignClient3")
    public R testFeignClient3(){
        R r = ossFileFeignClient.test3(teacherService.getById(1));
        return r;
    }


//    springmvc接收参数

//    get方式的参数 url?k=v
//    url?p1=xxx&p2=xxx
    @GetMapping("test1")
    public R test1(String p1, @RequestParam("p2") String p){//从请求参数中根据形参名获取参数值入参
        System.out.println("get方式的参数列表 :p1 => " + p1+",p =>" + p);
        return R.ok();

    }
//    url?name=xxx&intro=xxx 形参前没有指定注解的默认都是从请求参数中获取属性值使用
    @GetMapping("test2")
    public R test2(Teacher teacher){
        System.out.println("Get 请求方式的参数teacher = " + teacher);
        return R.ok();
    }
//    post 方式的参数: 一种是请求体提交的json字符串,另一种和get一样
//    url?p1=xxx 请求体中{name:xxx,intro:xxx}
    @PostMapping("test3")
    public R test3(String p1,@RequestBody Teacher teacher){
        System.out.println("Post请求方式的参数 p1 = " + p1);
        System.out.println("post 请求方式的参数 teacher = " + teacher);
        return R.ok();
    }

//    url?ids=1,2,3,4 在springmvc 中接收参数如果使用集合List或Map,必需 通过@RequestParma标注key
    @DeleteMapping("test4")
    public R test4(@RequestParam("ids")List<Integer> ids){
        System.out.println("ids = " + ids);
        return R.ok();
    }

}
